package games.platformer.actions;

import vooga.actions.*;
import vooga.core.Sound;

/**
 * Defines how a jump action should work.
 * These actions add to the velocity once and put the PlayerCharacter in the air.  These action starts once.
 * @author bshelton
 * @author Jonathan Odom
 *
 */
public class JumpAction implements Action{
	
	protected games.platformer.entities.PlayerCharacter myCharacter;
	protected double myDefaultMagnitude;
	protected double myDirection;
	boolean active;
	String mySound;

	/**
	 * Creates an action for the entity to be changed to the direction and defaultMagnitude
	 * @param entity object on which the action occurs
	 * @param direction the Vector direction to move
	 * @param defaultMagnitude the speed the object should move
	 */
	public JumpAction(games.platformer.entities.PlayerCharacter character, double direction, double defaultMagnitude, String sound)
	{
		myCharacter = character;
		myDirection = direction;
		myDefaultMagnitude = defaultMagnitude;
		active = false;
		mySound = sound;
	}
	
	public void start()
	{
		if(!active)
		{
			fire();
			active = true;
		}
		
	}
	
	public void stop()
	{
		active = false;
	}
	
	public void fire()
	{
		(new Sound(mySound)).play();
			vooga.geom.Vector newVector = new vooga.geom.Vector(myDirection,myDefaultMagnitude);
			newVector = myCharacter.getVelocity().add(newVector);
			myCharacter.setVelocity(newVector);
	}
	
}
